﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using OpenSoftStore.Orm;
using OpenSoftStore.Orm.Model;
using System.Linq;
using OpenSoftStore.Orm.View;
using System.Data;


namespace OpenSoftStore.BusinessLogic.Report
{
    public class ReportLogic : ABusinessLogic
    {

        public IEnumerable<V_WorkReport> GetWorkReport(string whereStr = "")
        {
            string sql = " select A.Name as AdminName, M.CardId, M.Name as MemberName, Item.ItemName as ServiceName,";
            sql += " CSTR(B.AddTime) + '～～' + CSTR(B.PayTime) as ServiceTime, B.CashPay,B.ValuePay,B.BankPay, B.Remark  ";
            sql += " from ((T_Admin as A inner join T_BillItem as Item on A.Id=Item.AdminId) ";
            sql += " inner join T_Bill as B on B.Id=Item.BillId)  ";
            sql += " inner join T_Member as M on M.Id=B.MemberId";
            whereStr += " and B.State='已结算'";
            return Spa.SelectWhere<V_WorkReport>(sql + whereStr);
        }

        public IEnumerable<V_Admin> GetBroNumReport(string whereStr = "")
        {
            string sql = " SELECT  A.Id,brok.Type,Sum(brok.BroNum) as SumBroNum, A.Name, T.Name as RoleName";
            sql += "  FROM ((T_Borakerage as brok  inner join T_Admin as A on A.Id= brok.AdminId) ";
            sql += "  inner join T_Tree as T on T.Id=A.TreeId)";
            sql += "  left join T_Bill as B on B.Id=brok.BillId";
            sql += whereStr;
            sql += "  group by  A.Id,brok.Type,A.Name,T.Name";
            return Spa.SelectWhere<V_Admin>(sql);
        }

        public IEnumerable<V_Borakerage> GetBroNumDetailReport(string whereStr = "")
        {
            string sql = " SELECT  brok.*,A.Name as AdminName,P.Name as ProductName";
            sql += " FROM ((T_Borakerage as brok left join T_Bill as B on brok.BillId=B.Id)";
            sql += " inner join T_Admin as A on A.Id= brok.AdminId)";
            sql += " left join T_Product as P on P.Id=brok.ProductId ";
            return Spa.SelectWhere<V_Borakerage>(sql + whereStr);
        }

        public DataTable GetStoreIOReport(string whereStr = "")
        {
            string sql = "";
            return Spa.RunSqLcmdDataSet(sql + whereStr).Tables[0];
        }
    }
}
